{include file="common/blank" /}
<title>添加权限节点</title>
</head>
<body>
<div class="page-container">
	<form action="" method="post" class="form form-horizontal" id="form-category-add">
		<div id="tab-category" class="HuiTab">
			<!--隐藏域 id-->
			<input type="hidden" name="id" id="id" value="{$info.id}">
			<div class="tabBar cl">
				<span>基本设置</span>
			</div>
			<div class="tabCon">
				<div class="row cl">
					<label class="form-label col-xs-4 col-sm-3">
						<span class="c-red">*</span>
						父级菜单：</label>
					<div class="formControls col-xs-8 col-sm-9">
						<span class="select-box">
						<select class="select" id="parent_id" name="parent_id">
							{volist name='data' id='vo'}
							<option value="{$vo.id}" {if condition="$vo.id eq $info.parent_id"}selected{/if}>{$vo.name}</option>
							{/volist}
						</select>
						</span>
					</div>
					<div class="col-3">
					</div>
				</div>
				<div class="row cl">
					<label class="form-label col-xs-4 col-sm-3">
						<span class="c-red">*</span>
						url：</label>
					<div class="formControls col-xs-8 col-sm-9">
						<input type="text" class="input-text" value="{$info.url}" placeholder="admin/admin/delUser" id="url" name="url">
					</div>
					<div class="col-3">
					</div>
				</div>
				<div class="row cl">
					<label class="form-label col-xs-4 col-sm-3">
						<span class="c-red">*</span>
						名称：</label>
					<div class="formControls col-xs-8 col-sm-9">
						<input type="text" class="input-text" value="{$info.name}" placeholder="功能名称" id="name" name="name">
					</div>
					<div class="col-3">
					</div>
				</div>
			</div>
		</div>
		<div class="row cl">
			<div class="col-9 col-offset-3">
				<input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;" onclick="check()">
			</div>
		</div>
	</form>
</div>
{include file="common/footer" /}
<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="/static/lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="/static/lib/jquery.validation/1.14.0/jquery.validate.js"></script>
<script type="text/javascript" src="/static/lib/jquery.validation/1.14.0/validate-methods.js"></script>
<script type="text/javascript" src="/static/lib/jquery.validation/1.14.0/messages_zh.js"></script>
<script type="text/javascript">
$(function(){
	$('.skin-minimal input').iCheck({
		checkboxClass: 'icheckbox-blue',
		radioClass: 'iradio-blue',
		increaseArea: '20%'
	});
	
	$("#tab-category").Huitab({
		index:0
	});
	$("#form-category-add").validate({
		rules:{
			url:{
				required:true,
			},
			name:{
				required:true,
			},
		},
		onkeyup:false,
		focusCleanup:true,
		success:"valid",
		submitHandler:function(form){
			//$(form).ajaxSubmit();
			// var index = parent.layer.getFrameIndex(window.name);
			//parent.$('.btn-refresh').click();
			// parent.layer.close(index);
		}
	});

});


function check(){
	var url = $.trim($('#url').val());
	var parent_id = $('#parent_id').val();
	var name = $.trim($('#name').val());
	var reg = /^[\u4E00-\u9FA5]{1,5}$/;
	if (name==''||url=='') {
		// alert('请填写信息');
		layer.msg('请填写信息',{icon:2,time:2000});
		return false;
	}
	if(!reg.test(name)) {
	    // alert("名称只支持中文字符");
		layer.msg('名称只支持中文字符',{icon:2,time:2000});
	    return false;
	}

    //获取隐藏域的id、
    var id=$("#id").val();
	$.post(
        "{:url('admin/admin/editPermission')}",
		{parent_id:parent_id,url:url,name:name,id:id},
		function (data) {
			var msg= data.msg;
	        if(data.code == 1){
	            layer.msg(msg, {
				  icon: 1,
				  time: 2000 //2秒关闭（如果不配置，默认是3秒）
				}, function(){
				  	var index = parent.layer.getFrameIndex(window.name);
					parent.$('.btn-refresh').click();
					window.parent.location.reload();
					parent.layer.close(index);
				}); 
	        }else{
	            layer.msg(msg,{icon:2,time:2000});
	        }
	});
		
}
</script>
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>